package com.cgc.venus.server.ci.service;

import com.cgc.venus.server.ci.inter.CodeSourceService;
import com.cgc.venus.server.ci.model.dao.CodeSourceDao;
import com.cgc.venus.server.ci.model.entity.CodeSource;
import com.cgc.venus.server.ci.model.vo.CodeSourceVO;
import com.cgc.venus.server.core.base.AbstractBaseService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 业哥 on 2018/5/22.
 */
@Service
public class CodeSourceServiceImpl extends AbstractBaseService implements CodeSourceService {
    @Autowired
    private CodeSourceDao codeSourceDao;

    @Override
    public PageInfo<CodeSource> findByKey(String key, String teamId, int pageNum, int rowNum) {
        PageHelper.startPage(pageNum, rowNum, true, true);
        List<CodeSource> list = codeSourceDao.findByKey(key, teamId);
        PageInfo<CodeSource> pageInfo = new PageInfo(list);
        return pageInfo;
    }

    @Override
    public List<CodeSourceVO> findByTeamId(String teamId) {
        List<CodeSource> css = codeSourceDao.findByKey("", teamId);
        List<CodeSourceVO> csvs=new ArrayList<>();
        if(css!=null){
            for(CodeSource cs:css){
                CodeSourceVO csv=new CodeSourceVO();
                BeanUtils.copyProperties(cs,csv,"codeUrl","codeUserName","codePwd","codeType","team","createTime","lastUpdateTime","createUser","updateUser","remark");
                csvs.add(csv);
            }
        }
        return csvs;
    }

}
